package de.java.shortys.utils.view;

import java.awt.Component;
import java.awt.Toolkit;

import javax.swing.ImageIcon;

public final class ViewUtils {

	/**
	 * private constructor.
	 */
	private ViewUtils() {
		// Empty
	}

	public static void setLocation(ViewLocationUtillityConstants location,
			Component component) {
		component.setLocation(getX(location, component),
				getY(location, component));
	}

	private static int getX(ViewLocationUtillityConstants location,
			Component component) {
		switch (location) {
		case LOCATION_CENTER:
			return Toolkit.getDefaultToolkit().getScreenSize().width / 2
					- component.getSize().width / 2;
		}

		return 0;
	}

	private static int getY(ViewLocationUtillityConstants location,
			Component component) {
		switch (location) {
		case LOCATION_CENTER:
			return Toolkit.getDefaultToolkit().getScreenSize().height / 2
					- component.getSize().height / 2;
		}

		return 0;
	}

	public static ImageIcon getIconFromString(String icon) {
		return new ImageIcon(Thread.currentThread().getContextClassLoader()
				.getResource(icon));
	}

	public static ImageIcon getIconFromString(String icon, int width, int height) {
		return new ImageIcon(new ImageIcon(Thread.currentThread()
				.getContextClassLoader().getResource(icon)).getImage()
				.getScaledInstance(width, height, 100));
	}
}
